from PySide6.QtWidgets import QApplication, QVBoxLayout, QWidget, QLabel
import PySide6.QtGui as QtGui
import sys
import os


class CustomWidget(QWidget):
    def __init__(self) -> None:
        super().__init__()
        self.setWindowTitle('QLabel and Images')

        # 1. 由于未知原因，QPixmap 无法识别相对路径的图片，故通过拼接绝对路径的方式展示图片
        abs_file_path = os.path.dirname(os.path.abspath(__file__))
        image_path = os.path.join(abs_file_path, 'resources', 'Zelda.jpg')
        print(f'拼接后的绝对路径：{image_path}')
        # 上面的代码等效于指定绝对路径
        # image_path = "D:\\WorkSpace\\Python\\pyside6_learn\\01_BV16d4y1s73t_202403\\images\\minions.png"

        image_label = QLabel()
        # image_label.setPixmap(QtGui.QPixmap(image_path))
        # 图片大小的处理
        image_label.setPixmap(QtGui.QPixmap(image_path).scaled(800, 800))


        # 2. 界面布局
        layout = QVBoxLayout()
        layout.addWidget(image_label)
   
        self.setLayout(layout)

app = QApplication(sys.argv)

window = CustomWidget()
window.show()

app.exec()
